/**
 * 已废弃
 */
// v1.0.0
let ideModuleDir = process.argv[1].replace("gulp\\bin\\gulp.js", "").replace("gulp/bin/gulp.js", "");

//引用插件模块
const gulp = require("gulp");
const fs = require("fs");
const path = require("path");
const childProcess = require("child_process");
const uglify = require('gulp-uglify-es').default;
const jsonminify = require("gulp-jsonminify");
const image = require("gulp-image");
const rev = require("gulp-rev");
const revdel = require("gulp-rev-delete-original");
const revCollector = require('gulp-rev-collector');
const del = require("del");

const isTs = fs.existsSync(workSpaceDir, "tsconfig.json");

gulp.task("del", (cb) => {
	// TODO 不是ts文件，则不执行
	console.log(process.argv);
	asdf;
	let delList = `${workSpaceDir}/build/**`;
    del(delList, { force: true }).then(paths => {
		cb();
	}).catch((err) => {
		throw err;
	})
});


gulp.task("tsc", ["del"], (cb) => {
    let commandSuffix = ".cmd";
	if (process.platform === "darwin") {
		commandSuffix = "";
	}
	let tscPath = path.join(ideModuleDir, ".bin", `tsc${commandSuffix}`);
	let tsconfitPath = path.join(workSpaceDir, "src", "tsconfig.json");
	return exec(`"${tscPath}" -b "${tsconfitPath}"`, {
		cwd: workSpaceDir,
		shell: true,
		encoding: "utf8"
	}, function(error, stdout, stderr) {
		if (error) console.log("error", error);
		if (stdout) console.log("stdout", stdout);
		if (stderr) console.log("stderr", stderr);
		cb();
	});
});

gulp.task("copy", ["tsc"], (cb) => {
	return gulp.src(`${workSpaceDir}/build/{actionScript,uiScript}`)
		.pipe(`${workSpaceDir}/bin`);
});

// 起始任务
gulp.task("pubLayaMe", ["copy"] , () => {
	console.log("All tasks completed!");
});